﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Miris.HumanMilkAnalyser.DataModel;
using Miris.HumanMilkAnalyser.Service;
using Miris.HumanMilkAnalyser.Service.Shared;
using Miris.HumanMilkAnalyser.WPF.Model;

namespace Miris.HumanMilkAnalyser.WPF.ViewModel.TestItemViewModel
{
    public class TestItemEnergyViewModel : TestItemSingleViewModel
    {
        /// <summary>
        /// Initializes a new instance of the EnergyTestItemViewModel class.
        /// </summary>
        public TestItemEnergyViewModel(IDataService dataService, IList<AnalysisItem> analysisItemList, MilkStage milkStage)
            : base(dataService, analysisItemList, milkStage) { }

        protected override void InitializeParameters()
        {
            base.InitializeParameters();

            TestResultUnit = "kcal/100ml";
            TestItemName = AnalysisItemDefinition.EnergyItemName;
            SetAnalysisItem();
        }

        /// <summary>
        /// Set RangeStartValue & RangeEndValue based on CurrentMilkStage.
        /// </summary>
        protected override void SetTestResultRangeValue()
        {
            if (CurrentMilkStage == MilkStage.Unmature)
            {
                //RangeStartValue = 58.8;
                //RangeEndValue = 73;

                RangeStartValue = ConfigFileUtility.GetValue<double>(ConfigurationConstant.EnergyUnmatureMilkRangeStartValue);
                RangeEndValue = ConfigFileUtility.GetValue<double>(ConfigurationConstant.EnergyUnmatureMilkRangeEndValue);
            }
            else if (CurrentMilkStage == MilkStage.Transitional)
            {
                //RangeStartValue = 67.8;
                //RangeEndValue = 83;

                RangeStartValue = ConfigFileUtility.GetValue<double>(ConfigurationConstant.EnergyTransitionalMilkRangeStartValue);
                RangeEndValue = ConfigFileUtility.GetValue<double>(ConfigurationConstant.EnergyTransitionalMilkRangeEndValue);
            }
            else if (CurrentMilkStage == MilkStage.Mature)
            {
                //RangeStartValue = 44.6;
                //RangeEndValue = 119.2;

                RangeStartValue = ConfigFileUtility.GetValue<double>(ConfigurationConstant.EnergyMatureMilkRangeStartValue);
                RangeEndValue = ConfigFileUtility.GetValue<double>(ConfigurationConstant.EnergyMatureMilkRangeEndValue);
            }
        }

        /// <summary>
        /// Set MinValue & MaxValue based on CurrentMilkStage.
        /// </summary>
        protected override void SetTestResultMinMaxValue()
        {
            base.SetTestResultMinMaxValue();

            //MaxValue = CurrentMilkStage == MilkStage.Mature ? 150 : 100;

            if (CurrentMilkStage == MilkStage.Unmature)
            {
                MaxValue = ConfigFileUtility.GetValue<double>(ConfigurationConstant.EnergyUnmatureMilkMaxValue);
            }
            else if (CurrentMilkStage == MilkStage.Transitional)
            {
                MaxValue = ConfigFileUtility.GetValue<double>(ConfigurationConstant.EnergyTransitionalMilkMaxValue);
            }
            else if (CurrentMilkStage == MilkStage.Mature)
            {
                MaxValue = ConfigFileUtility.GetValue<double>(ConfigurationConstant.EnergyMatureMilkMaxValue);
            }
        }
    }
}
